/*
 *
 * *******************************************************************
 *   @项目名称: BHex Android
 *   @文件名称: BhexSdk.java
 *   @Date: 11/29/18 3:21 PM
 *   @Author: chenjun
 *   @Copyright（C）: 2018 BlueHelix Inc.   All rights reserved.
 *   注意：本内容仅限于内部传阅，禁止外泄以及用于其他的商业目的.
 *  *******************************************************************
 *
 */

package io.bhex.sdk;

import android.app.Activity;
import android.content.Context;

import io.bhex.baselib.core.CApplication;
import io.bhex.baselib.network.params.UploadParam;
import io.bhex.baselib.utils.DevicesUtil;
import io.bhex.sdk.account.UserInfo;
import io.bhex.sdk.data_manager.NetWorkApiManager;
import io.bhex.sdk.data_manager.RateAndLocalManager;
import io.bhex.sdk.data_manager.RateDataManager;
import io.bhex.sdk.data_manager.SymbolDataManager;

public class BhexSdk {
    /**
     * app onCreate
     * @param context
     * @param config
     */
    private static Context mContext;
    public static String netType;
    private static OnNoCookieListener noCookieListener;
    private static OnResponseErrorListener responseErrorListener;
    private static Config mConfig;

    public static void InitConfig(Context context, Config config, boolean bhex){
        if (config == null)
            return;

        mContext = context;
        mConfig = config;
        UrlsConfig.init(bhex,config);
        netType = DevicesUtil.GetNetworkType(context);
        RateAndLocalManager.GetInstance(context);
    }

    public static Config getConfig(){
        return mConfig;
    }

    public static void NoCookieNotity(Context activity,String caller){
        if(noCookieListener != null)
            noCookieListener.OnNoCookie(activity, caller);
    }

    public static void NoCookieNotity(Activity activity,String caller , int requestCode){
        if(noCookieListener != null)
            noCookieListener.OnNoCookie(activity, caller, requestCode);
    }

    public static void SetNoCookieListener(OnNoCookieListener listener){
        noCookieListener = listener;
    }
    public interface OnNoCookieListener{
        void OnNoCookie(Context activity, String caller);
        void OnNoCookie(Activity activity, String caller, int requestCode);
    }

    public static void ResponseErrorNotity(String url, String errorCode){
        if(responseErrorListener != null)
            responseErrorListener.OnUploadResponseError(url, errorCode);
    }

    public static void NetRequestNotity(UploadParam param){
        if(responseErrorListener != null && param != null)
            responseErrorListener.OnUploadNetRequest(param);
    }

    public static void SetUploadResponseErrorListener(OnResponseErrorListener listener){
        responseErrorListener = listener;
    }
    public interface OnResponseErrorListener{
        void OnUploadResponseError(String url, String errorCode);
        void OnUploadNetRequest(UploadParam param);
    }
    /**
     * Mainactivity onCreate
     */
    public static void Start(){

        SymbolDataManager.GetInstance().Init();
        RateDataManager.GetInstance();
        NetWorkApiManager.getQuoteInstance();
        if (UserInfo.isLogin()) {
            SymbolDataManager.GetInstance().getFavorites();
        }
    }

    /**
     * Mainactivity onstop
     */
    public static void Stop(){
        SymbolDataManager.GetInstance().release();
        RateDataManager.GetInstance().release();
        NetWorkApiManager.releaseTradeInstance();
    }

    public static Context getContext(){
        return mContext;
    }
}
